
    function uploader(picker, list, btn, info,auto,fileNumLimit) {
        var $ = jQuery,
            $list = $("#" + list),
            $btn = $("#" + btn),
            //优化retina,在retina下这个值是2
            ratio = window.devicePixelRatio || 1,
            //缩略图大小
            thumbnailWidth = 100 * ratio,
            thumbnailHeight = 100 * ratio,
            state = "pending",
            info = $("."+info),
            fileCounter = 0,
            uploader;
        //初始化Web Uploader
        uploader = WebUploader.create({
            //不压缩image
            resize: false,
            //文件接收的服务器
            server: "/common/upload",
            //选择文件的按钮
            //pick: "#picker"
            pick: "#" + picker,
            auto: auto||true,
            fileNumLimit: fileNumLimit||1,
            accept: {
                title: "Images",
                extensions: "gif,jpg,jpeg,bmp,png",
                mimeTypes: "image/*"
            }
        })
        //当有文件添加进来的时候
        uploader.on("fileQueued", function(file) {
            fileCounter++;
            //alert(fileCounter)
            var $li = $(
                '<div id="' + file.id + '" class="file-item">' +
                '<img src="" alt="" />' +
                '<div class="text-center fileName">' + file.name + '</div>' +
                '<div class="del"><span>删除</span></div>' +
                //'<span class="uploaderSuccess"></span>'+
                '</div>'
            );
            var delwrap = $li.find(".del")
            $li.on("mouseenter", function() {
                delwrap.stop().animate({ height: 25 })
            })
            $li.on("mouseleave", function() {
                delwrap.stop().animate({ height: 0 })
            })
            var delbtn = delwrap.find("span")
            delbtn.on("click", function() {
                //alert("hi")
                uploader.removeFile(file);
 
            })
 
            var $img = $li.find("img");
            $list.append($li);
            //创建缩略图
            uploader.makeThumb(file, function(error, src) {
                if (error) {
                    $img.replaceWith("<span>不能预览</span>");
                    return
                }
                $img.attr("src", src);
            }, thumbnailWidth, thumbnailHeight)
            showfileNum()
 
        });
        //console.log( uploader.getFiles().length );  
        function showfileNum() {
            info.text("共选择" + fileCounter + "个文件")
        }
        
        function removeFile(file){
        var $li = $('#'+file.id);
        $li.off().find('.del span').off().end().remove();
        }
        uploader.on("fileDequeued", function(file) {
            fileCounter--;
            //alert(fileCounter)
            showfileNum()
            removeFile(file);
        })
 
        //文件上传过程中创建进度条实时显示
        uploader.on("uploadProgress", function(file, percentage) {
            var $li = $("#" + file.id);
            var $percent = $li.find(".progress .progress-bar");
            //避免重复创建
            if (!$percent.length) {
                $percent = $('<div class="progress progress-striped active">' +
                    '<div class="progress-bar" role="progressbar" style="width:0%">' +
                    '</div>' +
                    '</div>').appendTo($li).find(".progress-bar");
            }
            //$li.find('span.state').text('上传中...')
            $percent.css('width', percentage * 100 + '%')
        });
        uploader.on("uploadSuccess", function(file) {
        	$( '#'+file.id ).find('p.state').text('已上传');
            //$('#' + file.id).append('<span class="uploaderSuccess"></span>')
            //$('#' + file.id).find('span.state').text("已上传")
            //$('#' + file.id).find('span.state').addClass('green')
        })
        uploader.on("uploadError", function(file) {
        	$( '#'+file.id ).find('p.state').text('上传出错');
            //$('#' + file.id).find(".fileName").append(' <img src="error-c-o.png" alt="" style="width:20px;"/>')
 
             //failnum.text(uploader.getStats().uploadFailNum)
            //$('#' + file.id).find('span.state').text("上传出错")
            //$('#' + file.id).find('span.state').addClass("red")
        })
        uploader.on("uploadComplete", function(file) {
            $('#' + file.id).find('.progress').fadeOut();
        })
        uploader.on("all", function(type) {
            if (type === 'startUpload') {
                state = 'uploading';
            } else if (type === 'stopUpload') {
                state = 'paused'
            } else if (type === 'uploadFinished') {
                state = 'done'
            }
            if (type === 'uploading') {
                $btn.text('暂停上传')
            } else {
                $btn.text('开始上传')
            }
 
        })
        $btn.on('click', function() {
            if (state === 'uploading') {
                uploader.stop();
            } else {
                uploader.upload();
				state="done"
				//alert("click")
            }
        });
        $(".retry").on("click",function(){
 
            uploader.retry();
            //alert(uploader.retry().length)
        })
    }